package com.youmeek.demo.web.servlet.Test;

import java.util.Arrays;

public class Sort {
    public static void main(String[] args) {
        int[] array = {1,2,6,5,8,9,3};
        int[] newArray = sort(array);
        for (int i = 0;i < newArray.length; i++){
            System.out.println(newArray[i]);
        }
    }





    public static int[] sort(int[] sourceArray){
        int[] arr = Arrays.copyOf(sourceArray, sourceArray.length);
        for (int i = 0; i < arr.length - 1; i++) {
            boolean flag = true;
            for (int j = 0; j < arr.length - i - 1; j++) {
                if (arr[j] > arr[j + 1]) {
                    int tmp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = tmp;
                    flag = false;
                }
            }
            if (flag) {
                break;
            }
        }
        return arr;
    }
}

